package com.ling.sbbyyds.mapper.user;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ling.sbbyyds.entity.community.CommunityPosts;
import com.ling.sbbyyds.entity.users.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface UserMapper extends Mapper<User>,BaseMapper<User> {

    User findLogin(User user);

    Integer enroll(User user);

    User findUserByPhone(String phone);

    List<CommunityPosts> selectPostsListById(Long id);

    Integer selectPostsCountById(Long id);

    /**
     * 修改密码
     * @param phone  手机号
     * @param password  新密码
     * @return
     */
    @Update("update sbb_user set password = #{password} where phone = #{phone} ")
    Integer updatePassword(@Param("phone") String phone, @Param("password") String password);

    /**
     * 获取用户信息
     * @param userId  用户id
     * @return
     */
    @Select("select avatar,id,user_name as userName from sbb_user where id = #{userId} ")
    User selectUserInfo(@Param("userId") Long userId);


    /**
     * 获取用户名
     * @param userId  用户id
     * @return
     */
    @Select("select user_name from sbb_user where id = #{userId} ")
    String selectUserName(@Param("userId") Long userId);

}
